package com.ljy.mapper;

import com.ljy.dto.LeaseOrdersPageDTO;
import com.ljy.entity.LeaseOrders;
import com.ljy.vo.LeaseOrdersDetailVO;
import com.ljy.vo.LeaseOrdersVO;
import org.apache.ibatis.annotations.*;

import java.time.LocalDateTime;
import java.util.List;

@Mapper
public interface LeaseOrdersMapper {

    @Insert("insert into lease_orders(user_id, lease_id, status, order_num,name, image, pickup, create_time " +
            ", amount, phone, full_name, dormitory, spec_time, time_number) " +
            "values (#{userId},#{leaseId},#{status},#{orderNum},#{name},#{image},#{pickup},#{createTime}," +
            "#{amount},#{phone},#{fullName},#{dormitory},#{specTime},#{timeNumber})")
    @Options(useGeneratedKeys = true,keyProperty = "id")
    void insert(LeaseOrders leaseOrders);

    @Select("select id, user_id, lease_id, status,order_num ,name, image, pickup, create_time, pay_time, end_time, amount, " +
            "phone, full_name, dormitory, spec_time, time_number, reason from lease_orders where id=#{ordersId}")
    LeaseOrders getById(Integer ordersId);


    void update(LeaseOrders orders);

    @Select("select id, user_id, lease_id, status, name, image,  create_time,  end_time, amount, spec_time, time_number" +
            " from lease_orders  where user_id=#{userId} order by create_time desc ")
    List<LeaseOrdersVO> list(Integer userId);

    @Select("select id,create_time from lease_orders where create_time<#{timeout} and status=#{status}")
    List<LeaseOrders> getTimeoutOrder(LocalDateTime timeout,Short status);

    @Select("select id,create_time from lease_orders where end_time<#{timeout} and status=#{status}")
    List<LeaseOrders> getLeaseTimeout(LocalDateTime timeout,Short status);

    List<LeaseOrders> selectPage(LeaseOrdersPageDTO dto);
    @Select("select id from lease_orders where order_num=#{orderNum}")
    Integer getIdByNum(String orderNum);

}
